{% extends current_module.base_template %}
{% load i18n material_form material_form_internal material_frontend %}

{% load base_debug data_filter %}

{% block breadcrumbs_items %}
<a class="active" href="{% url view.model|frontend_urlname:'list' %}">{{ view.model|verbose_name_plural|title }}</a>
{% endblock %}


{% block content %}
{% block left-panel %}
{% if view.filterset.form.fields|length == 0 and view.viewset.list_actions is None %}
<div class="left-panel wide">
{% else %}
<div class="left-panel">
{% endif %}
    <div class="card list-card">
        <div class="card-content">
            <dmc-datatable config="{{ datatable_config|to_json_attr }}" checkboxes="true">
                <table id="table" class="table bordered" data-form-control="datatable" style="width:100%">
                    <thead>
                        <tr>

                            {% for header, header_title in headers %}
                                {% if header == 'pk' %}
                                    <th style="width: 40px; padding-right: 0px;" class="">
                                    <label>
                                    <input class="filled-in" type="checkbox" id="action-toggle">
                                    <span></span>
                                </label>
                                    </th>
                                {% else %}
                                    <th data-name="{{ header }}" class="{{ header }}">{{ header_title|title }}</th>
                                {% endif %}
                            {% endfor %}
                        </tr>
                    </thead>
                    <tbody>
                        <tr style="display:none"><td></td></tr> {# fix for invalid colpan on datatable init #}
                        {% for item, row in data %}

                        <tr>

                            {% for column_name, item in row.items %}
                                {% if column_name == 'pk' %}
                                <td class="dt-body-center">
                                <label>
                                    <input class="filled-in" type="checkbox" name="pk" id="_selected_action_1" value="">
                                    <span></span>
                                </label>
                            </td>
                                {% else %}
                                    <td>
                                        {% if column_name in view.datalist.list_display_links %}
                                        <a href="#">{{ item }}</a>
                                        {% else %}
                                        {{ item }}
                                        {% endif %}
                                    </td>
                                {% endif %}
                            {% endfor %}
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </dmc-datatable>
        </div>
    </div>
</div>
{% endblock left-panel %}
{% block right-panel %}
    {{ view.filterset.form.fields.count }}
{% if view.filterset.form.fields|length > 0 or view.viewset.list_actions is not None %}
    <div class="right-panel">
        {% if view.filterset.form.fields|length > 0 %}
            <dmc-form>
                <form action="." method="get" data-control-form>
                    <div class="card form-card">
                        <div class="card-content">
                        <span class="card-title">{% trans 'Filter' %}</span>
                            <dmc-select>
                                {{ view.filterset.form.as_p }}
                            </dmc-select>
                        <div class="right-align">
                            <button type="submit" class="btn btn-default">{% trans 'Filter' %}</button>
                        </div>
                        </div>
                    </div>
                </form>
            </dmc-form>
        {% endif %}

        {% if view.viewset.list_actions is not None %}
        <div class="card form-card" id="actionCard">
            <div class="card-content">
                <div class="card-title">{% trans 'Action' %}</div>
                    <dmc-select>
                        <select name="action_url">
                            <option disabled selected>{% trans 'Choose your option' %}</option>

                            <option value="{{ view.viewset.list_actions.1 }}">{% trans view.viewset.list_actions.0 %}</option>

                        </select>
                    </dmc-select>
                <div class="card-actions right-align">
                    <button class="btn" type="submit" name="action">{% trans 'Go' %}</button>
                </div>
            </div>
        </div>
        {% endif %}
    </div>
{% endif %}
{% endblock right-panel %}
{% block action_btn %}
<div class="fixed-action-btn">
    {% if add_url %}
      <a class="btn-floating btn-large waves-effect waves-light red z-depth-2" href="{{ add_url }}"><i class="large material-icons">add</i></a>
    {% endif %}
</div>
{% endblock %}
{% endblock %}

{% block footer %}
    <div style="display:none" id="_action_token">
        <input type='hidden' name='csrfmiddlewaretoken' value='{{ csrf_token }}' />
    </div>

{% endblock footer %}